import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'
// 用户权限认证
import store from '../store'
Vue.use(VueRouter)

const router = new VueRouter({
  mode: 'history',
  routes
})

// 用户权限认证
const list = ['mine'] // 保存的是需要有权限才能访问的页面.
// const isLogin = false // 是否已登录
// 全局前置守卫
router.beforeEach((to, from, next) => {
  const isLogin = store.state.user.isLogin
  console.log('是否登录：', isLogin)
  if (list.indexOf(to.name) !== -1 && !isLogin) {
    next({
      name: 'login',
      params: {
        to
      }
    })
  } else {
    next()
  }
})
export default router
